package com.fz.study.project.controller;


import com.fz.study.project.entity.Blog;
import com.fz.study.project.entity.Result;
import com.fz.study.project.entity.dto.UserDTO;
import com.fz.study.project.service.ITbBlogService;
import com.fz.study.project.utils.UserHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-03-04
 */

@Tag(name = "探店博客")
@RestController
@RequiredArgsConstructor
@RequestMapping("/tb-blog")
public class BlogController {

    private final ITbBlogService blogService;

    @Operation(summary ="保存博客信息")
    @PostMapping
    public Result saveBlog(@RequestBody Blog blog){
        UserDTO user = UserHolder.getUser();
        blog.setUserId(user.getId());
        blogService.save(blog);
        return Result.success("存储个人博客成功");
    }

    @Operation(summary = "用户点赞")
    @PutMapping("/like/{id}")
    public Result likeBlog(@PathVariable("id") Long id){

        return Result.success(blogService.likeBlog(id));
    }

}
